#ifndef PARTICLESOURCE_H
#define PARTICLESOURCE_H

#include <vector>
#include <string>

#include "../Input/PicParams.h"
#include "../Parallel/ParallelMPI.h"
#include "../Species/Species.h"
#include "../Tool/Log.h"

using namespace std;
class ParticleSource
{

public:

    ParticleSource(PicParams* params_, ParallelMPI* pmpi_, PhysicalField* fields_, vector<Species*>* vecSpecies_, ParticleSourceParameter ps_param_) :
        params(params_),
        pmpi(pmpi_),
        fields(fields_),
        vecSpecies(vecSpecies_),
        ps_param(ps_param_)
    {
            count_of_particles_to_insert_s1.resize(params->dims_space[0]);
            count_of_particles_to_insert.resize(params->dims_space[0]);
            number_particle_in_each_cell.resize(params->dims_space[0]);

            load_cell_start.resize(params->n_dim_field);
            load_cell_end.resize(params->n_dim_field);

            cell_min.resize(params->n_dim_field);
            cell_length.resize(params->n_dim_field);

    };
    virtual ~ParticleSource(){};

    int species1;
    //dependent species group
    vector<int> species_group_dependent;
    //Particles new_particles;
    vector<int> count_of_particles_to_insert_s1;

    vector<int> number_particle_in_each_cell;
    vector<int> count_of_particles_to_insert;
    vector<int> indexes_of_particles_to_erase;

    //Particle number in one cell, different from particle number in one bin for 2D case
    int numPart_in_each_cell;

    //Method called in the main pic loop to apply ParticleSource at each timestep
    virtual void emitLoad(int itime){};


    //relevant PSI, emitting number of two species may be relevant
    //such as number_particle_emit(A) = relCoff * number_particle_emit(B)
    ParticleSource *relParticleSource;
    string relSpecies;
    virtual void setRelParticleSource(ParticleSource* relevantParticleSource)
    {
        relParticleSource = relevantParticleSource;
    }


    int n_ParticleSource;

    double weight_const;

    std::vector<int> load_cell_start;
    std::vector<int> load_cell_end;

    std::vector<double> cell_min;
    std::vector<double> cell_length;

    PicParams* params;
    ParallelMPI* pmpi;
    PhysicalField* fields;
    vector<Species*>* vecSpecies;
    const ParticleSourceParameter ps_param;


private:


};

#endif
